export default {
    data() {
        return {
            isShow: false,
            timer: null
        }
    },
    mounted() {
        window.addEventListener('scroll', this.handleScroll)
    },
    destroyed() {
        window.removeEventListener('scroll', this.handleScroll)
    },
    methods: {
        handleScroll() {
            let scrollTop =
                window.pageYOffset ||
                document.documentElement.scrollTop ||
                document.body.scrollTop
            if (scrollTop > 800) {
                this.isShow = true
            } else {
                this.isShow = false
            }
        },
        goTop() {
            let _this = this
            cancelAnimationFrame(_this.timer)
            _this.timer = requestAnimationFrame(function fn() {
                var oTop = document.body.scrollTop || document.documentElement.scrollTop
                if (oTop > 0) {
                    scrollTo(0, oTop - 50)
                    _this.timer = requestAnimationFrame(fn)
                } else {
                    cancelAnimationFrame(_this.timer)
                }
            })
        }
    }
}